package com.ruoyi.system.module.appliction.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.system.module.appliction.entity.Application;
import com.ruoyi.system.module.appliction.service.ApplicationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/zxm/application")
public class ApplicationController extends BaseController {

    @Resource
    private ApplicationService menuService;





    @GetMapping("list")
    public AjaxResult list(Application application) {


//        menuService.selectRole(roleId);

        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUserid();
        application.setParentId(Long.valueOf(1));

        List<Application> menus = menuService.selectMenuList(application,userId);

        return AjaxResult.success(menus);
    }


    /**
     * 根据菜单编号获取详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:menu:render')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable Long menuId) {
        List<Application> applications = menuService.selectMenuById(menuId);

        Application menu1  = menuService.selectMenuByIdA(menuId);

        return AjaxResult.success(menuService.selectMenuById(menuId));

    }
    @GetMapping(value = "/normal")
    public AjaxResult getNormal(){

        return AjaxResult.success(menuService.selectByNormal());
    }

    /**
     *
     * 应用使用日志
     */
//    @PreAuthorize("@ss.hasPermi('system:zxm:log')")
    @RequestMapping("/number/{menuId}")
    public AjaxResult getMenu(@PathVariable("menuId") Long menuId) {
        //用户名，用户id,应用id，应用名，次数
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUserid();
        String username =  loginUser.getUsername();
        //先根据menuID查找这条应用数据
        Application application =   menuService.selectMenuByIdA(menuId);
        //查询menuID和menuname
        application.getMenuId();
        application.getMenuName();


        return toAjax(menuService.selectFrequency(userId,username,application.getMenuId(),application.getMenuName()));
    }

    /**
     *其他应用列表
     */

    @GetMapping(value = "/router/{menuId}")
    public AjaxResult getInfo1(@PathVariable Long menuId) {


        return AjaxResult.success(menuService.selectMenuByIdA(menuId));

    }
//    @RequestMapping("search/number")
//    public TableDataInfo list(SysApplicationCounts sysApplicationCounts){
//        startPage();
//        List<SysApplicationCounts> result = menuService.searchNumber(sysApplicationCounts);
//
//        return getDataTable(result);
//    }
}
